package com.psytech.app.task.tasks_mds.entity;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.psytech.app.task.tasks_mds.entity.embeddable.TodoKey;

@Entity
@Table(name="todo")
@IdClass(TodoKey.class)
public class EntityTodo implements Serializable  {

	@Id
	@AttributeOverrides({
		@AttributeOverride(name = "taskUid",
				column = @Column(name="taskUid")),
				@AttributeOverride(name = "userUid",
						column = @Column(name="userUid"))
	})
	private String taskUid;
	private String userUid;

	/*
	@ManyToOne(targetEntity=EntityTask.class)
	private EntityTask task;
	 */

	public EntityTodo(final TodoKey key) {
		taskUid=key.getTaskUid();
		userUid=key.getUserUid();
	}

	public EntityTodo() {
		// TODO Auto-generated constructor stub
	}

	/*
	public EntityTask getTask() {
		final EntityTask task = new EntityTask();
		task.setUid(taskUid);
		return task;
	}
	 */
	public String getUserUid(){
		return userUid;
	}

	public String getTaskUid() {
		return taskUid;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((taskUid == null) ? 0 : taskUid.hashCode());
		result = prime * result + ((userUid == null) ? 0 : userUid.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final EntityTodo other = (EntityTodo) obj;
		if (taskUid == null) {
			if (other.taskUid != null)
				return false;
		} else if (!taskUid.equals(other.taskUid))
			return false;
		if (userUid == null) {
			if (other.userUid != null)
				return false;
		} else if (!userUid.equals(other.userUid))
			return false;
		return true;
	}


}
